package il.ac.tau.cg.ex3.entities.styles.drawables;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import il.ac.tau.cg.ex3.entities.styles.Color;

public class ImageDrawable implements Drawable
{
	private BufferedImage image;
	
	public ImageDrawable(BufferedImage image)
	{
		this.image = image;
	}
	
	public ImageDrawable(File imageFile) throws IOException
	{
		this.image = ImageIO.read(imageFile);
	}
	
	@Override
	public Color sample(double x, double y)
	{
		int ix = (int)(x * (image.getWidth() - 1));
		int iy = (int)(y * (image.getHeight() - 1));
		
		return new Color(image.getRGB(ix, iy));
	}
}
